package com.isdepci.project.system.utils;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class AddressUtils {


    private final static String baiDuAK = "Bl1xA5ycL8pUe8XkRR3fIBUaUHhulyab";
//    private final static String baiDuAK = "kgTEcr2O82QcRE1rZtkxO3BIQq6Sww55";

    public static void main(String[] args) {
        getAddress("116.32715863448607,39.990912172420714");
        getAddress("117.134448,36.656554");
        getAddress("120.389458,36.072227");
    }

    public static void getAddress(String longitudeLatitude) {
        String[] longitudeArr = longitudeLatitude.split(",");
        longitudeLatitude = longitudeArr[1]+","+longitudeArr[0];
        String resultStr = sendMessage("http://api.map.baidu.com/reverse_geocoding/v3/?ak="+baiDuAK+"&coordtype=wgs84ll&location="+longitudeLatitude+"&output=json");
    }
    public static String sendMessage(String url) {
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        HttpGet httpGet = new HttpGet(url);  //url:请求地址 get请求
        httpGet.addHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8");
        try {
            HttpResponse res = httpClient.execute(httpGet);
            String rtn = EntityUtils.toString(res.getEntity());
            return rtn;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            httpGet.releaseConnection();
        }
        return null;
    }





}
